<template>
	<view class="All-container">
		<uni-swipe-action>
			<uni-swipe-action-item :left-options="options2" :right-options="options2" :show="isOpened"
				:auto-close="false" @change="change" @click="bindClick">
				<template v-slot:left>
					<view class="left-slot">
						<image @tap="love" v-if="detail.collect === false" src="../../static/dishes/点击收藏.png"
							mode="widthFix"></image>
						<image @tap="love" v-else src="../../static/dishes/收藏爱心.png" mode="widthFix"></image>
					</view>
				</template>
				<template v-slot:right>
					<view class="right-slot">
						<image @click="del" src="../../static/dishes/删除.png" mode="widthFix"></image>
					</view>
				</template>
				<view class="content-box">
					<view class="left-image">
						<image src="../../static/dishes/卤香凤爪.png" mode="widthFix"></image>
					</view>
					<view class="details">
						<view class="name">{{detail.name}}</view>
						<view class="average">{{detail.average}}</view>
						<view class="collect">
							<image v-if="detail.collect === false" src="../../static/dishes/未收藏.png" mode="widthFix">
							</image>
							<image v-else src="../../static/dishes/爱心收藏组.png" mode="widthFix"></image>
						</view>
						<view class="comments">
							<text>{{detail.comment1}}</text>
							<text>{{detail.comment2}}</text>
						</view>
						<view class="price">
							<image src="../../static/dishes/人民币.png" mode="widthFix"></image>
							<text>{{detail.price}}</text>
						</view>
					</view>
					<view class="back">
						<view v-if="detail.num > 0" class="counter">
							<view class="count-add">
								<image @tap="add" src="../../static/dishes/smalladd.png" class="btn-add"
									mode="widthFix"></image>
								<view class="number">{{detail.num}}</view>
								<image @tap="reduce" src="../../static/dishes/del.png" class="btn-del" mode="widthFix">
								</image>
							</view>
						</view>
						<view v-else class="count-only">
							<image @tap="add" src="../../static/dishes/bigadd.png" mode="widthFix"></image>
						</view>
					</view>

				</view>
			</uni-swipe-action-item>
		</uni-swipe-action>
	</view>
</template>

<script>
	export default {
		props: {
			detail: {
				type: Object,
				default: {},
			},
		},
		name: "single-dish",
		data() {
			return {
				options2: [{
					style: {
						backgroundColor: '#FA8C16',
					}
				}],
				isOpened: 'none',
			};
		},
		methods: {
			change(e) {
				this.isOpened = e;
				console.log('返回：', e);
			},
			bindClick(e) {
				console.log(e);
				uni.showToast({
					title: `点击了${e.position === 'left' ? '左侧' : '右侧'} ${e.content.text}按钮`,
					icon: 'none'
				});
			},
			add() {
				this.$store.commit({
					type: 'add',
					arguments: {
						id: this.detail.id
					}
				});
			},
			reduce() {
				this.$store.commit({
					type: 'reduce',
					arguments: {
						id: this.detail.id
					}
				});
			},
			love() {
				this.$store.commit({
					type: 'love',
					arguments: {
						id: this.detail.id
					}
				})
			},
			del() {
				this.$store.commit({
					type: 'del',
					arguments: {
						id: this.detail.id
					}
				})
			},



		},

	}
</script>

<style lang="scss" scoped>
	.All-container {
		width: 686rpx;
		height: 268rpx;
		margin: 32rpx auto 0;
	}

	.right-slot {
		width: 98rpx;
		height: 268rpx;
		background-color: #FA8C16;
		border-top-right-radius: 48rpx;
		border-bottom-right-radius: 48rpx;
		display: flex;
		align-items: center;

		image {
			margin: auto;
			display: block;
			width: 52rpx;
		}
	}

	.left-slot {
		width: 98rpx;
		height: 268rpx;
		background-color: #FA8C16;
		border-top-left-radius: 48rpx;
		border-bottom-left-radius: 48rpx;
		display: flex;
		align-items: center;

		image {
			margin: auto;
			display: block;
			width: 52rpx;
		}
	}

	.content-box {
		height: 268rpx;
		width: 686rpx;
		position: relative;
		display: flex;
		background-color: #F5F5F5;

		.left-image {
			image {
				width: 228rpx;
				height: 228rpx;
				border-radius: 20rpx;
				margin: 20rpx 0 0 20rpx;
			}

		}

		.details {
			display: flex;
			flex-direction: column;
			align-content: space-around;
			height: 268rpx;
			margin-left: 20rpx;
			margin-top: 20rpx;

			.name {
				font-size: 40rpx;
				color: #121B36;
			}

			.average {
				font-size: 16px;
				opacity: 0.6;
			}

			.comments {
				font-size: 14px;
				color: #BFBFBF;
			}

			.collect {
				width: 296rpx;
				height: 34rpx;

				image {
					width: 180rpx;
				}
			}

			.price {
				font-size: 20px;
				color: #FA8C16;

				image {
					width: 16rpx;
				}
			}
		}

		.back {
			position: absolute;
			height: 268rpx;
			width: 98rpx;
			right: 0;

			.counter {
				height: 268rpx;
				width: 98rpx;
				background-color: #F5F5F5;
				display: flex;

				.count-add {
					margin: auto;
					width: 56rpx;
					border-radius: 75rpx;
					border: 2rpx solid #D9D9D9;
					background: #F5F5F5;
					display: flex;
					flex-direction: column;
					align-content: space-between;

					.btn-add {
						margin: auto;
						display: block;
						width: 48rpx;
						height: 48rpx;
					}

					.btn-del {
						margin: auto;
						display: block;
						width: 48rpx;
						height: 48rpx;
					}

					.number {
						font-size: 18px;
						line-height: 100%;
						text-align: center;
						color: #FA8C16;
					}
				}

			}

			.count-only {
				height: 268rpx;
				width: 98rpx;
				display: flex;
				align-content: center;

				image {
					display: block;
					margin: auto;
					width: 52rpx;
				}
			}
		}

	}
</style>
